<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>grid</title>
    <style>
        .card {
            display: flex;
            flex-wrap: wrap;
            margin: 0 auto;
            width: 300px;
        }
        .card li {
            list-style: none;
            width: 100px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            box-sizing: border-box;
            border: 4px #ccc solid;
            margin-left: -4px;
            margin-top: -4px;
        }
        .card li:nth-child(3n+1) {
            margin-left: 0;
        }
        .card li:hover {
            border-color: red;
            z-index: 2;
        }
    </style>
</head>
<body>
<ul class="card">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
</ul>
</body>
</html>
